package h0802;

import java.util.Arrays;
import java.util.Scanner;

/**
  * @description 字符串筛选排序
  * @author 不知名帅哥
  * @date 2024/8/2 9:17
  * @version 1.0
*/
public class StringFilterSort {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        String s = sc.nextLine();
        int k =sc.nextInt();

        char[] chars = s.toCharArray();
        Arrays.sort(chars);
        char c;
        if (k> chars.length){
            c = chars[chars.length - 1];
        }else {
            c = chars[k-1];
        }
        System.out.println(getIndex(s, c));
    }

    //可以使用indexOf s.indexOf()
    private static int getIndex(String s, char c) {
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i)== c){
                return i;
            }
        }
        return -1;
    }
}
